package com.dzu.medium;

/**
 * @author ZhaoDong
 * @date 2022/11/7 9:47
 * @description 7. 整数反转
 */
public class Test7 {
    public static void main(String[] args) {
        System.out.println(reverse(123));

    }

    public static int reverse(int x) {

        int res = 0;
        while (x != 0) {
            if (res < Integer.MIN_VALUE / 10 || res > Integer.MAX_VALUE / 10) {
                return 0;
            }
            int temp = x % 10;
            res = res * 10 + temp;
            x /= 10;
        }
        return res;
    }
}
